package com.first.nell.info.idcard

import android.graphics.Bitmap
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations
import com.first.nell.base.BaseViewModel
import com.first.nell.data.*
import com.first.nell.network.ApiUserReposity

class IdentityCardModel : BaseViewModel() {

    companion object {
        val IDENTITY_IDCARD = "IDENTITY_IDCARD"
        val IDENTITY_PASSPORT = "IDENTITY_PASSPORT"
        val IDENTITY_DRIVING = "IDENTITY_DRIVING"


        val IMAGE_IDCARD_FRONT = "IMAGE_IDCARD_FRONT"
        val IMAGE_IDCARD_BACK = "IMAGE_IDCARD_BACK"

        val IMAGE_PASSPORT_FRONT = "IMAGE_PASSPORT_FRONT"

        val IMAGE_DRVING_FRONT = "IMAGE_DRVING_FRONT"
        val IMAGE_DRVING_BACK = "IMAGE_DRVING_BACK"
    }

    /** 认证类型 */
    var mFirstNellIdentityType = ""

    /** 图片类型 */
    var mFirstNellImageType = ""

    /** 图片本地路径 */
    var mFirstNellImageFirstNellPathFirstNellFront = ""

    /** 图片本地路径 */
    var mFirstNellImageFirstNellPathFirstNellBack = ""

    /** 图片oss路径 */
    var mFirstNellImageFirstNellUrlFirstNellFront = ""

    /** 图片oss路径 */
    var mFirstNellImageFirstNellUrlFirstNellBack = ""

    /** 图片oss路径 */
    var mFirstNellImageFirstNellBitmapFirstNellFront: Bitmap? = null

    /** 图片oss路径 */
    var mFirstNellImageFirstNellBitmapFirstNellBack: Bitmap? = null


    /** 上传图片 */
    private val mFirstNellUploadFirstNellImageFirstNellLiveData =
        MutableLiveData<ReqImageUpload>()

    /** 上传图片 */
    val onFirstNellUploadFirstNellImageFirstNellLiveData =
        Transformations.switchMap(mFirstNellUploadFirstNellImageFirstNellLiveData) { query ->
            ApiUserReposity.uploadFirstNellImage(this, query)
        }

    /** 上传图片 */
    fun uploadFirstNellImage(reqImageUpload: ReqImageUpload) {
        mFirstNellUploadFirstNellImageFirstNellLiveData.value = reqImageUpload
    }

    ////////////////////
    /** 保存图片 */
    private val mFirstNellSaveFirstNellImageFirstNellLiveData =
        MutableLiveData<ReqSaveImage>()

    /** 保存图片 */
    val onFirstNellSaveFirstNellImageFirstNellLiveData =
        Transformations.switchMap(mFirstNellSaveFirstNellImageFirstNellLiveData) { query ->
            ApiUserReposity.saveFirstNellImage(this, query)
        }

    /** 保存图片 */
    fun saveFirstNellImage(reqSaveImage: ReqSaveImage) {
        mFirstNellSaveFirstNellImageFirstNellLiveData.value = reqSaveImage
    }
}